package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品控制器
 *
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2024/2/4 10:46:24
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
@Slf4j
@RequiredArgsConstructor
public class DishController {

    private final DishService dishService;

    /**
     * 创造
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> create(@RequestBody DishDTO dishDTO) {
        dishService.create(dishDTO);
        return Result.success();
    }

    /**
     * 页
     *
     * @param dishPageQueryDTO 菜页查询dto
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 删除批次
     *
     * @param ids ids
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteBatch(@RequestParam List<Long> ids) {
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * id信息
     *
     * @param id 身份证件
     * @return {@link Result}<{@link DishVO}>
     */
    @GetMapping("/{id}")
    public Result<DishVO> infoById(@PathVariable Long id) {
        DishVO dishVO = dishService.infoById(id);
        return Result.success(dishVO);
    }

    /**
     * 使现代化
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> update(@RequestBody DishDTO dishDTO) {
        dishService.update(dishDTO);
        return Result.success();
    }


    /**
     * 按类别id列表
     *
     * @param categoryId 类别id
     * @return {@link Result}<{@link List}<{@link Dish}>>
     */
    @GetMapping("/list")
    public Result<List<Dish>> listByCategoryId(Long categoryId) {
        List<Dish> dishVOList = dishService.listByCategoryId(categoryId);
        return Result.success(dishVOList);
    }
}
